<?php
namespace LPCISII\PHP2012Bundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use LPCISII\PHP2012Bundle\Entity\Utilisateur;

use Doctrine\Common\Persistence\ObjectManager;

class UtilisateurFixtures extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }
    
    public function load(ObjectManager $manager)
    {
        $user = new Utilisateur();
        $user->setLogin('test');
        $factory = $this->container->get('security.encoder_factory');
        $encoder = $factory->getEncoder($user);
        $password = $encoder->encodePassword('test', $user->getSalt());
        $user->setMdp($password);
        $user->setNom('Barthelemy');
        $user->setPrenom('Gabriel');
        $user->setRue('2 route de Mirecourt');
        $user->setType(0);
        $user->setVille('Hergugney');
        $user->setEmail('barthelemy.gabriel@gmail.com');
        $manager->persist($user);
        
        $manager->flush();
    }

    public function getOrder() {
        return 1;
    }

}